<?php

class CQuestionsubet extends Zend_Db_Table
{

    protected $_name;

    protected $_primary;

    public function _setup()
    {

        $this->_name=R_PRE."Question_bet";

        $this->_primary="id";

        parent::_setup();

    }

    public function createFbbet($data)
    {

        $betid = $this->insert($data);

        return $betid;

    }

    public function getAllBetCounts($where = ""){

            $db=$this->getAdapter();

            $select = $db->select();

            $select->from($this->_name,'COUNT(*)');

            if($where!=''){

                    $select->where($where);

            }

            return $db->fetchOne($select);
    }

    public function getAllBets($from,$counts,$where=''){

        $db=$this->getAdapter();
        $select = $db->select();

        $select->from($this->_name,'*');

        $select->order("add_time DESC");
        $join_table_team = R_PRE."Question_subject";
        $join_table_member = R_PRE."members";
        $select->joinLeft($join_table_team." AS T", "T.id = $this->_name.sceneid", array('title'=>'T.title','tanswers'=>'T.answers'));
        $select->joinLeft($join_table_member." AS M", "M.uid = $this->_name.uid", array('username'=>'M.username'));

        if($where!=''){

            $select->where($where);

	}

        if($counts!=0){

            $select->limit($counts, $from);

        }
        return $db->fetchAll($select);
    }
    
    public function delfbbets($where=''){

            $db=$this->getAdapter();

            $scenceidString=join(',',$scenceidArray);
            $result=$db->query("DELETE FROM $this->_name WHERE id IN ($scenceidString)");

            return $result;

    }
}